package com.huatai.datadevelop.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huatai.datadevelop.entity.TableConfigEntity;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;


@Mapper
public interface TableConfigMapper extends BaseMapper<TableConfigEntity> {

    /**
     * 分页查询数据
     * @param fild
     * @param tableName
     * @param
     * @return
     */
    @Select(" select ${fild} from ${tableName} ${limitStr}")
    List<HashMap<String,Object>> getDataListById(@Param("fild") String fild, @Param("tableName") String tableName,@Param("limitStr") String limitStr);

    /**
     * 根据表名称获取数据总条数
     * @param tableName
     * @return
     */
    @Select(" select count(*) as dataCount from ${tableName} ")
    JSONObject getDataCountByTableName(@Param("tableName") String tableName);

    /**
     * 动态数据更新
     * UPDATE stic_simple SET name='张武' , icon="管理员" where name='李四4'
     * @param tableName
     * @param assignment
     * @param WHERETO
     */
    @Update(" update ${tableName}  set  ${assignment}  WHERE ${WHERETO} ")
    void updateData(@Param("tableName") String tableName,
                    @Param("assignment") String assignment,
                    @Param("WHERETO") String WHERETO);

    /**
     * 插入数据
     * INSERT INTO stic_simple (name,icon,status) VALUES ('李四4', 'T恤衫', '衣服'),('李四5', 'T恤衫', '衣服'),('李四6', 'T恤衫', '衣服');
     * @param tableName
     * @param fild
     * @param value
     */
    @Insert(" INSERT INTO ${tableName} (${fild}) VALUES ${value}")
    void insertData(@Param("tableName") String tableName,@Param("fild") String fild, @Param("value") String value);

    /**
     * 插入数据
     */
    @Insert(" ${sqlStr} ")
    Boolean insertDataSql(@Param("sqlStr") String sqlStr);
}
